package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.mappers.BlackListMapper;
import com.tanhua.dubbo.mappers.UserInfoMapper;
import com.tanhua.model.db.BlackList;
import com.tanhua.model.db.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;

    @Autowired
    private UserInfoMapper userInfoMapper;


    //根据用户id，查询黑名单列表
    public IPage<UserInfo> findByUserId(Long userId, Integer page, Integer pagesize) {
        //1、构造分页参数
        Page<UserInfo> pageParam = new Page(page,pagesize);
        //2、调用mapper查询
        return userInfoMapper.findBlackList(pageParam,userId);
    }

    //删除黑名单
    public void delete(Long userId, Long blackUserId) {
        //delete from tb_black_list where user_id= ? and black_user_id=?
        QueryWrapper<BlackList> qw = new QueryWrapper<>();
        qw.eq("user_id",userId);
        qw.eq("black_user_id",blackUserId);
        blackListMapper.delete(qw);
    }
}
